using AutoMapper;
using CoreManager.Models.DTOs;
using CoreManager.Models.Entities;

namespace CoreManager.Models.Mappings
{
    /// <summary>
    /// 菜单映射配置
    /// </summary>
    public class MenuMappingProfile : Profile
    {
        public MenuMappingProfile()
        {
            // Menu 实体到 MenuDto 的映射
            CreateMap<Menu, MenuDto>()
                .ForMember(dest => dest.Children, opt => opt.MapFrom(src => src.Children));

            // CreateMenuDto 到 Menu 实体的映射
            CreateMap<CreateMenuDto, Menu>()
                .ForMember(dest => dest.Id, opt => opt.Ignore())
                .ForMember(dest => dest.CreateTime, opt => opt.Ignore())
                .ForMember(dest => dest.UpdateTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateUserId, opt => opt.Ignore())
                .ForMember(dest => dest.UpdateUserId, opt => opt.Ignore())
                .ForMember(dest => dest.IsDeleted, opt => opt.Ignore())
                .ForMember(dest => dest.Parent, opt => opt.Ignore())
                .ForMember(dest => dest.Children, opt => opt.Ignore());

            // UpdateMenuDto 到 Menu 实体的映射
            CreateMap<UpdateMenuDto, Menu>()
                .ForMember(dest => dest.Id, opt => opt.Ignore())
                .ForMember(dest => dest.CreateTime, opt => opt.Ignore())
                .ForMember(dest => dest.UpdateTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateUserId, opt => opt.Ignore())
                .ForMember(dest => dest.UpdateUserId, opt => opt.Ignore())
                .ForMember(dest => dest.IsDeleted, opt => opt.Ignore())
                .ForMember(dest => dest.Parent, opt => opt.Ignore())
                .ForMember(dest => dest.Children, opt => opt.Ignore())
                .ForAllMembers(opt => opt.Condition((src, dest, srcMember) => srcMember != null));
        }
    }
}